package com.hz.edu.controller;

import com.hz.api.model.request.ApiResponse;
import com.hz.edu.service.CourseService;
import com.hz.edu.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/edu")
public class StudentController {

    @Resource
    StudentService studentService;

    @Resource
    CourseService courseService;

    @PostMapping("/student/select-course")
    public String selectCourse(@RequestParam("courseId") Integer courseId, @RequestParam("studentId") Integer studentId) {
        int select = studentService.selectCourse(studentId, courseId);
        return select > 0 ? ApiResponse.ok(select) : ApiResponse.intError();
    }

    @PostMapping("/student/cancel-course")
    public String cancelCourse(@RequestParam("courseId") Integer courseId, @RequestParam("studentId") Integer studentId) {
        return ApiResponse.ok(studentService.cancelCourse(studentId, courseId));
    }

    @GetMapping("/all-courses")
    public String allCourses() {
        return ApiResponse.ok(courseService.allCourses());
    }

    @GetMapping("/student/selected")
    public String selected(@RequestParam("studentId") Integer studentId) {
        return ApiResponse.ok(studentService.selectedCourses(studentId));
    }

    @GetMapping("/student/selected-info")
    public String selectedInfo(@RequestParam("courseId") Integer courseId, @RequestParam("studentId") Integer studentId) {
        return ApiResponse.ok(studentService.selectedCourseInfo(studentId, courseId));
    }



}
